package com.example.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.entity.PsInspectiontaskMain;
import com.example.entity.PsSystemconfig;
import com.example.service.PsInspectiontaskMainService;
import com.example.service.PsSystemconfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 巡检任务主表controller(ps_inspectiontask_main)
 */
@RestController
@Slf4j
@CrossOrigin
public class PsInspectiontaskMainController {

    @Resource
    PsInspectiontaskMainService psInspectiontaskMainService;

    @Resource
    PsSystemconfigService psSystemconfigService;

    /**
     * 修改
     * @param psInspectiontaskMain
     * @return
     */
    
    @PostMapping("/updmain")
    public int updatemain(@RequestBody PsInspectiontaskMain psInspectiontaskMain){
        psInspectiontaskMainService.updateByPrimaryKeySelective(psInspectiontaskMain);
        return 1;
    }

    /**
     * 查询配置表状态
     * @return
     */
    @RequestMapping("/selectconfig")
    public List<PsSystemconfig> selectConfig(){
       return psSystemconfigService.listpsc();
    }
    /**
     * 巡视任务制定和分配查询
     * @return
     */
    @RequestMapping("/selectbypage")
    public IPage<PsInspectiontaskMain> selectByPage(PsInspectiontaskMain psInspectiontaskMain,Integer current, Integer size){

        LambdaQueryWrapper<PsInspectiontaskMain> userLambdaQueryWrapper = Wrappers.lambdaQuery();
        System.out.println("isstime="+psInspectiontaskMain.getIssuedtime());
        System.out.println("fintime="+psInspectiontaskMain.getFinishtime());

        Page<PsInspectiontaskMain> mapPage = new Page<>(current,size);
        IPage<PsInspectiontaskMain> mapIPage = psInspectiontaskMainService.selectByPage(psInspectiontaskMain,mapPage,userLambdaQueryWrapper);
        System.out.println("总页数： "+mapIPage.getPages());
        System.out.println("总记录数： "+mapIPage.getTotal());
        mapIPage.getRecords().forEach(System.out::println);
        return mapIPage;
    }


    /*@RequestMapping("/listmain")
    public List<PsInspectiontaskMain> listmain(PsInspectiontaskMain psInspectiontaskMain){
        psInspectiontaskMain.setInspectiontaskcode("RW0245");
        psInspectiontaskMain.setInspectiontaskname("西渭一线任务巡检");
        psInspectiontaskMain.setTaskstatus(1l);
        psInspectiontaskMain.setIssuedbyname("线路管理员测试用户01");
//        //字符串转Date类型
//        String time = "2024-05-19 ";
//        String time2 = "2024-03-19 ";
//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd ");
//        try {
//            Date newTime = format.parse(time);
//            Date newTime2 = format.parse(time2);
//            psInspectiontaskMain.setIssuedtime(newTime2);
//            psInspectiontaskMain.setFinishtime(newTime);
//        } catch (ParseException e) {
//            e.printStackTrace();
//        }
        return psInspectiontaskMainService.listmain(psInspectiontaskMain);
    }*/
}
